有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java从消息数组中返回一条消息

我只是需要有一个类型消息数组。所以我想回复他们的留言。有人能帮我怎么做吗

public static Message getContent(String user, String pswd, String sub, String to)
        throws MessagingException, IOException {
    Session imapSession1 = TestMail.greenMail.getImap().createSession();
    Store store = imapSession1.getStore("imap");
    store.connect("foo", "password");
    Folder inbox = store.getFolder("INBOX");
    inbox.open(Folder.READ_ONLY);
    // Getting only unread messages.
    Flags flags = new Flags();
    flags.add(Flag.SEEN);
    FlagTerm flagTerm = new FlagTerm(flags, false);
    Message[] msgs = inbox.search(flagTerm);
    Message ms = msgs[0];
    return ms;

}

我试图返回如上所示的第一条消息,但它抛出了IndexOutOfBoundsException:0 有人能帮我吗。提前谢谢


共 (0) 个答案